package com.lagou.testpool;

import com.lagou.Utils.DBCPUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class TestDBCP {
    /*
    *  测试DBCP连接池
    * */
    public static void main(String[] args) throws Exception {
        //1.从DBCP连接池中拿到连接
        Connection connection = DBCPUtils.getConnection();

        //2.获取Statement对象
        Statement statement=connection.createStatement();

        //3.查询所有员工的姓名
        String sql="select ename from employee";
        ResultSet resultSet=statement.executeQuery(sql);

        //4.处理结果集
        while(resultSet.next()){
            String str1=resultSet.getString("ename");
            System.out.println("员工姓名:"+str1);
        }

        //5.释放资源
        DBCPUtils.close(connection,statement,resultSet);
    }
}
